const webpack = require('webpack')
const path = require('path')

function resolve(dir) {
    return path.join(__dirname, dir)
}

module.exports = {
    chainWebpack(config) {
        config.resolve.alias
            .set('views', resolve('src/views'))
            .set('components', resolve('src/components'))
            .set('common', resolve('src/common'))
            .set('api', resolve('src/api'))
            .set('base', resolve('src/base'))
            .set('utils', resolve('src/utils'))

        config
            .plugin('context')
            .use(webpack.ContextReplacementPlugin, [
                /moment[/\\]locale$/,
                /zh-cn/
            ])
    },
    devServer: {
        proxy: {
            '/api': {
                target: 'http://app11.qiyuesuo.net',
                changeOrigin: true,
                ws: true,
                pathRewrite: {
                    '^/api': ''
                }
            }
        }
    }
}
